<template>
  <div>
    <!--头部-->
    <div
        style="
        display: flex;
        height: 60px;
        line-height: 60px;
        border-bottom: 1px solid #eee;
      "
    >
      <div style="width: 300px; display: flex; padding-left: 30px">
        <div style="width: 60px">
          <img
              src="../../assets/007.jpg"
              alt=""
              style="width: 50px; position: relative; top: 5px; right: 0;border-radius: 10%;"
          />
        </div>
        <div style="flex: 1">欢迎来到快乐买系统</div>
      </div>
      <div style="flex: 1">
        <el-menu
            :default-active="'/front/home'"
            class="el-menu-demo"
            mode="horizontal"
            router
        >
          <el-menu-item index="/front/home">首页</el-menu-item>
          <el-menu-item index="/front/seckill">新品秒杀</el-menu-item>
          <el-menu-item index="/front/cart">购物车</el-menu-item>
          <el-menu-item index="/front/order">订单管理</el-menu-item>
          <el-menu-item index="/front/comments">我的评价</el-menu-item>
          <el-menu-item index="/front/dingzhi">定制</el-menu-item>
          <el-menu-item index="/front/mydingzhi">查看我的定制</el-menu-item>
        </el-menu>
      </div>
      <div style="width: 200px">
        <div v-if="!user.uaccount" style="text-align: right; padding-right: 30px">
          <el-button @click="$router.push('/login')">登录</el-button>
          <el-button @click="$router.push('/register')">注册</el-button>
        </div>
        <div v-else>
          <el-dropdown style="width: 150px; cursor: pointer; text-align: right">
            <div style="display: inline-block">
              <img class="MyAvatar"
                   :src="user.avatarUrl"
                   alt=""
                   style="
                  width: 30px;
                  border-radius: 50%;
                  position: relative;
                  top: 10px;
                  right: 5px;
                "
              />
              <span>{{ user.uaccount }}</span>
              <i class="el-icon-arrow-down" style="margin-left: 5px"></i>
            </div>
            <el-dropdown-menu
                slot="dropdown"
                style="width: 100px; text-align: center"
            >
              <el-dropdown-item style="font-size: 14px; padding: 5px 0">
                <router-link to="/front/center/person">个人中心</router-link>
              </el-dropdown-item>
              <el-dropdown-item style="font-size: 14px; padding: 5px 0">
                <router-link to="/front/address">我的地址</router-link>
              </el-dropdown-item>
              <el-dropdown-item style="font-size: 14px; padding: 5px 0">
                <span style="text-decoration: none" @click="logout">退出</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>

    <div style="width: 1000px; margin: 0 auto">
      <router-view/>
    </div>
  </div>

</template>

<script>


export default {
  name: "Front",
  data() {
    return {
      name: this.user = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
      user: "",
      pageNum: 1,
      pageSize: 12,
      total: 0,
    };
  },
  created() {
    this.load();
  },
  methods: {
    load() {
      this.user = localStorage.getItem("user")
          ? JSON.parse(localStorage.getItem("user"))
          : {};
    },
    logout() {
      this.$store.commit("logout");
      this.$message.success("退出成功");
    },

  },
};
</script>

<style>
.item {
  display: inline-block;
  width: 100px;

  text-align: center;
  cursor: pointer;
}

.item a {
  color: #1e90ff;
}

.item:hover {
  background-color: LightPink;
}

a {
  text-decoration: none;
}

.MyAvatar {
  margin-right: 7px;
  transition: all 0.6s;
}

.MyAvatar:hover {
  transform: scale(1.7);
}
</style>
